/**
 * fileName:  NutrientWriter.java
 * author:  Lei
 * Company:  Cloudland Studio
 * Createdate:  2014-6-3 下午10:55:05
 *
 * All rights Reserved, Designed By cloudland Copyright(C) 2010-2011
 *   
 * Modification  History:
 *     Date           Author        Version        
 * -------------------------------------------
 * 2014-6-3          Lei            1.0        
 *
 * Why & What is modified:
 * 1.0: 文件创建
 */
package org.cloudland.commercial.masterdata.store.write;

import javax.annotation.Resource;

import org.cloudland.commercial.masterdata.store.DatabaseWrite;
import org.cloudland.commercial.masterdata.store.entity.NutritionEntity;
import org.cloudland.jdbc.ibatis.masterdata.entity.NutritionDictEntity;
import org.cloudland.jdbc.ibatis.masterdata.handler.NutritionDictMapper;
import org.cloudland.util.Randoms;
import org.springframework.stereotype.Service;

 /**
 * <pre> 
 * 营养信息写入
 * </pre>
 * @ClassName  NutrientWriter
 * @author  Lei
 * @version  %I%, %G%
 * @see  
 * @since   JDK1.6
 *
 */
@Service
public class NutrientWriter implements DatabaseWrite<NutritionEntity> {
	
	@Resource(name = "nutritionDictMapper")
	private NutritionDictMapper nutritionMapper;

	/**
	 * <pre>
	 * TODO 请充分描述该构造函数的作用，及其参数的作用。
	 * </pre>
	 *   
	 */
	public NutrientWriter() {
		// TODO Auto-generated constructor stub
	}
	
	/**
	 * @param entity
	 */
	public void save(NutritionEntity entity) {
		
		String uuid = Randoms.uuid();
		entity.setId(uuid);
		short sort = Short.parseShort(entity.getSort().toString());
		
		NutritionDictEntity  entityDao = new NutritionDictEntity(entity.getId(), entity.getName(), entity.getDesc(), sort, entity.getType().code());
		nutritionMapper.add(entityDao);
	}
	
	/**
	 * @param entity
	 */
	public void update(NutritionEntity entity) {
		short sort = Short.parseShort(entity.getSort().toString());
		NutritionDictEntity  entityDao = new NutritionDictEntity(entity.getId(), entity.getName(), entity.getDesc(), sort, entity.getType().code());
		nutritionMapper.update(entityDao);
	}
	
	/**
	 * @param entity
	 */
	public void delete(NutritionEntity entity) {
		NutritionDictEntity  entityDao = new NutritionDictEntity(entity.getId(), entity.getName(), entity.getDesc(), (short) 1, entity.getType().code());
		nutritionMapper.delete(entityDao);
	}

}
